home *** CD-ROM | disk | FTP | other *** search
/ Aminet 1 (Walnut Creek) / Aminet - June 1993 [Walnut Creek].iso / aminet / mus / play / multiplsr.lha / med8play.asm < prev    next >
Assembly Source File  |  1992-09-14  |  50KB  |  1,808 lines

  1. * MultiPlayer
  2. * Copyright (C) 1992 Bryan Ford
  3. *
  4. * This program is free software; you can redistribute it and/or modify
  5. * it under the terms of the GNU General Public License as published by
  6. * the Free Software Foundation; either version 2 of the License, or
  7. * (at your option) any later version.
  8. *
  9. * This program is distributed in the hope that it will be useful,
  10. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  12. * GNU General Public License for more details.
  13. *
  14. * You should have received a copy of the GNU General Public License
  15. * along with this program; if not, write to the Free Software
  16. * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  17. *
  18. * See Player.doc for info on contacting the author.
  19. *
  20. * Note:  This playroutine was not originally written by me.  In general
  21. * these playroutines are public domain, so I am bringing the versions
  22. * modified for MultiPlayer under the General Public License.  In the
  23. * few cases of already-copyrighted playroutines, the above copyright
  24. * notice applies only to the parts of the file written by me.
  25. *
  26. * $Id: med8play.asm,v 4.2 92/07/19 16:37:38 BAF Exp Locker: BAF $
  27. *
  28.  
  29.         include "exec/types.i"
  30.         include "bry/macros.i"
  31.         include "player.i"
  32.  
  33.         xdef    _InitPlayer8,_RemPlayer8,_PlayModule8,_StopPlayer8,_ContModule8,_modnum8
  34.  
  35.         code    text
  36.  
  37. ;    pro8player.a
  38. ;    ~~~~~~~~~~~~
  39. ;    The player routine for OctaMED V1.0-3.0 5 - 8 channel songs.
  40. ;    Written by Teijo Kinnunen in 1992.
  41. ;
  42. ; THIS CODE MAY BE FREELY USED AND DISTRIBUTED!
  43.  
  44. ;============================================================================
  45. AUDDEV        EQU 0    ;1 = allocate channels using audio.device
  46. CHECK        EQU 1    ;1 = do range checkings (track, sample in mem etc.)
  47. IFFMOCT        EQU 1    ;1 = play IFF multi-octave samples correctly
  48. HOLD        EQU 1    ;1 = handle hold/decay
  49. PLAYMMD0    EQU 1    ;1 = play old MMD0 modules
  50. ;============================================================================
  51.  
  52. ;the MMD0 structure offsets
  53. mmd_id        EQU    0
  54. mmd_modlen    EQU    4
  55. mmd_songinfo    EQU    8
  56. mmd_blockarr    EQU    16
  57. mmd_smplarr    EQU    24
  58. mmd_expdata    EQU    32
  59. mmd_pstate    EQU    40 ; <0 = play song, 0 = don't play, >0 = play block
  60. mmd_pblock    EQU    42
  61. mmd_pline    EQU    44
  62. mmd_pseqnum    EQU    46
  63. mmd_actplayline    EQU    48
  64. mmd_counter    EQU    50
  65. mmd_songsleft    EQU    51
  66.  
  67. ;the MMD0song structure
  68. ;Instrument data here (504 bytes = 63 * 8)
  69. msng_numblocks    EQU    504
  70. msng_songlen    EQU    506
  71. msng_playseq    EQU    508
  72. msng_deftempo    EQU    764
  73. msng_playtransp    EQU    766
  74. msng_flags    EQU    767
  75. msng_flags2    EQU    768
  76. msng_tempo2    EQU    769
  77. msng_trkvol    EQU    770
  78. msng_mastervol    EQU    786
  79. msng_numsamples    EQU    787
  80.  
  81. ;Instrument data
  82. inst_repeat    EQU    0
  83. inst_replen    EQU    2
  84. inst_midich    EQU    4
  85. inst_midipreset    EQU    5
  86. inst_svol    EQU    6
  87. inst_strans    EQU    7
  88.  
  89. ;Audio hardware offsets
  90. ac_ptr    EQU    $00
  91. ac_len    EQU    $04
  92. ac_per    EQU    $06
  93. ac_vol    EQU    $08
  94. ac_end    EQU    $0C
  95. ac_rest    EQU    $10
  96. ac_mask    EQU    $14
  97. ac_rhw    EQU    $16
  98.  
  99. T03SZ    EQU    98
  100. T415SZ    EQU    18
  101.  
  102. ;**************************************************************************
  103. ;*
  104. ;*        8 CHANNEL PLAY ROUTINE
  105. ;*
  106. ;**************************************************************************
  107.  
  108. ; This code does the magic 8 channel thing (mixing).
  109. MAGIC_8TRK    MACRO
  110.         swap    d6
  111.         swap    d7
  112.         move.b    0(a3,d6.w),d0
  113.         add.b    0(a4,d7.w),d0
  114.         move.b    d0,(a1)+
  115.         swap    d6
  116.         swap    d7
  117.         add.l    d1,d6
  118.         add.l    d2,d7
  119.         ENDM
  120.  
  121. _ChannelO8    lea    trackdata8-DB(a6),a1
  122.         cmp.b    #8,d0
  123.         bge.s    xco8
  124.         lsl.b    #2,d0
  125.         adda.w    d0,a1
  126.         movea.l    (a1),a1
  127.         clr.w    trk_prevper(a1)
  128.         movea.l    trk_audioaddr(a1),a1
  129.         clr.w    ac_per(a1)
  130. xco8        rts
  131.  
  132. _PlayNote8:    ;d7(w) = trk #, d1 = note #, d3(w) = instr # a3 = addr of instr
  133.         movea.l    mmd_smplarr(a2),a0
  134.         add.w    d3,d3            ;d3 = instr.num << 2
  135.         add.w    d3,d3
  136.         move.l    0(a0,d3.w),d5        ;get address of instrument
  137.     IFNE    CHECK
  138.         beq.s    xco8
  139.     ENDC
  140. inmem8:        add.b    msng_playtransp(a4),d1    ;add play transpose
  141.         add.b    inst_strans(a3),d1    ;and instr. transpose
  142.     IFNE    CHECK
  143.         tst.b    inst_midich(a3)
  144.         bne.s    xco8        ;MIDI
  145.     ENDC
  146.         clr.b    trk_vibroffs(a5)    ;clr vibrato offset
  147.         move.l    d5,a0
  148.         subq.b    #1,d1
  149.     IFNE    CHECK
  150.         tst.w    4(a0)
  151.         bmi.s    xco8        ;Synth
  152.     ENDC
  153. tlwtst08:    tst.b    d1
  154.         bpl.s    notenot2low8
  155.         add.b    #12,d1    ;note was too low, octave up
  156.         bra.s    tlwtst08
  157. notenot2low8:    cmp.b    #62,d1
  158.         ble.s    endpttest8
  159.         sub.b    #12,d1    ;note was too high, octave down
  160. endpttest8:
  161.         moveq    #0,d2
  162.         moveq    #0,d3
  163.     IFNE    IFFMOCT
  164.         move.w    4(a0),d0    ;Soitin-struct in a0
  165.         bne.s    iff5or3oct    ;note # in d1 (0 - ...)
  166.     ENDC
  167.         lea    _periodtable+32-DB(a6),a1
  168.         move.b    trk_finetune(a5),d2    ;finetune value
  169.         add.b    d2,d2
  170.         add.b    d2,d2        ;multiply by 4...
  171.         ext.w    d2        ;extend
  172.         movea.l    0(a1,d2.w),a1    ;period table address
  173.         move.l    a1,trk_periodtbl(a5)
  174.         add.b    d1,d1
  175.         move.w    0(a1,d1.w),d5 ;put period to d5
  176.         move.l    a0,d0
  177.         addq.l    #6,d0        ;Skip structure
  178.         move.l    (a0),d1        ;length
  179.         add.l    d0,d1        ;sample end pointer
  180.         move.w    inst_repeat(a3),d2
  181.         move.w    inst_replen(a3),d3
  182.     IFNE    IFFMOCT
  183.         bra    gid_setrept
  184. gid_addtable    dc.b    0,6,12,18,24,30
  185. gid_divtable    dc.b    31,7,3,15,63,127
  186. iff5or3oct:    move.l    d7,-(sp)
  187.         moveq    #0,d7
  188.         move.w    d1,d7
  189.         divu    #12,d7    ;octave #
  190.         move.l    d7,d5
  191.         cmp.w    #6,d7    ;if oct > 5, oct = 5
  192.         blt.s    nohioct
  193.         moveq    #5,d7
  194. nohioct        swap    d5    ;note number in this oct (0-11) is in d5
  195.         move.l    (a0),d1
  196.         cmp.w    #6,d0
  197.         ble.s    nounrecit
  198.         moveq    #6,d0
  199. nounrecit    add.b    gid_addtable-1(pc,d0.w),d7
  200.         move.b    gid_divtable-1(pc,d0.w),d0
  201.         divu    d0,d1    ;get length of the highest octave
  202.         swap    d1
  203.         clr.w    d1
  204.         swap    d1
  205.         move.l    d1,d0        ;d0 and d1 = length of the 1st oct
  206.         move.w    inst_repeat(a3),d2
  207.         move.w    inst_replen(a3),d3
  208.         moveq    #0,d6
  209.         move.b    shiftcnt(pc,d7.w),d6
  210.         lsl.w    d6,d2
  211.         lsl.w    d6,d3
  212.         lsl.w    d6,d1
  213.         move.b    mullencnt(pc,d7.w),d6
  214.         mulu    d6,d0        ;offset of this oct from 1st oct
  215.         add.l    a0,d0        ;add base address to offset
  216.         addq.l    #6,d0        ;skip structure
  217.         add.l    d0,d1
  218.         lea    _periodtable+32-DB(a6),a1
  219.         move.b    trk_finetune(a5),d6
  220.         add.b    d6,d6
  221.         add.b    d6,d6
  222.         ext.w    d6
  223.         movea.l    0(a1,d6.w),a1
  224.         move.l    a1,trk_periodtbl(a5)
  225.         add.b    octstart(pc,d7.w),d5
  226.         add.b    d5,d5
  227.         move.w    0(a1,d5.w),d5
  228.         move.l    (sp)+,d7
  229.         bra.s    gid_setrept
  230. shiftcnt:    dc.b    4,3,2,1,1,0,2,2,1,1,0,0,1,1,0,0,0,0
  231.         dc.b    3,3,2,2,1,0,5,4,3,2,1,0,6,5,4,3,2,1
  232. mullencnt:    dc.b    15,7,3,1,1,0,3,3,1,1,0,0,1,1,0,0,0,0
  233.         dc.b    7,7,3,3,1,0,31,15,7,3,1,0,63,31,15,7,3,1
  234. octstart:    dc.b    12,12,12,12,24,24,0,12,12,24,24,36,0,12,12,24,36,36
  235.         dc.b    0,12,12,24,24,24,12,12,12,12,12,12,12,12,12,12,12,12
  236.     ENDC
  237.             even
  238. gid_setrept    add.l    d2,d2
  239.         add.l    d0,d2        ;rep. start pointer
  240.         cmp.w    #1,d3
  241.         bhi.s    gid_noreplen2
  242.         moveq    #0,d3        ;no repeat
  243.         bra.s    gid_cont
  244. gid_noreplen2    add.l    d3,d3
  245.         add.l    d2,d3        ;rep. end pointer
  246.  
  247. gid_cont    movea.l    trk_audioaddr(a5),a1 ;base of this channel's regs
  248.         move.l    d0,(a1)        ;put it in ac_ptr
  249.         cmp.l    d0,d3
  250.         bhi.s    repeat8
  251.  
  252.         tst.b    trk_split(a5)
  253.         beq.s    pn8_nosplit0
  254.         clr.l    ac_rest(a1)
  255.         subq.l    #1,d1
  256.         move.l    d1,ac_end(a1)
  257.         bra.s    retsn18
  258.  
  259. pn8_nosplit0    sub.l    d0,d1
  260.         lsr.l    #1,d1
  261.         move.w    d1,ac_len(a1)
  262.         move.l    #_chipzero,ac_rest(a1)
  263.         move.w    #1,ac_end(a1)
  264.         bra.s    retsn18
  265.  
  266. repeat8:    tst.b    trk_split(a5)
  267.         bne.s    pn8_split1
  268.         move.l    d3,d1
  269.         sub.l    d0,d1
  270.         lsr.l    #1,d1
  271.         move.w    d1,ac_len(a1)
  272.         move.l    d2,ac_rest(a1)    ;remember rep. start
  273.         sub.l    d2,d3
  274.         lsr.l    #1,d3
  275.         move.w    d3,ac_end(a1)    ;remember rep. length
  276.         bra.s    retsn18
  277.  
  278. pn8_split1    move.l    d2,ac_rest(a1)
  279.         move.l    d3,ac_end(a1)
  280. retsn18:    move.w    d5,ac_per(a1)    ;getinsdata puts period to d5
  281.         move.w    d5,trk_prevper(a5)
  282. retsn28:    rts
  283.  
  284. _IntHandler8:    movem.l    d2-d7/a2-a5,-(sp)
  285.         lea    DB,a6
  286.         lea    trksplit-DB(a6),a2
  287.         move.w    currchsize2-DB(a6),d4
  288. ; ================ 8 channel handling (buffer swap) ======
  289.         move.w    #800,d0
  290.         not.b    whichbuff-DB(a6)    ;swap buffer
  291.         bne.s    usebuff1
  292.         tst.b    (a2)+
  293.         beq.s    tnspl0
  294.         move.l    a1,$a0(a0)
  295.         move.w    d4,$a4(a0)
  296. tnspl0        lea    800(a1),a5
  297.         tst.b    (a2)+
  298.         beq.s    tnspl1
  299.         move.l    a5,$b0(a0)
  300.         move.w    d4,$b4(a0)
  301. tnspl1        adda.w    d0,a5
  302.         tst.b    (a2)+
  303.         beq.s    tnspl2
  304.         move.l    a5,$c0(a0)
  305.         move.w    d4,$c4(a0)
  306. tnspl2        adda.w    d0,a5
  307.         tst.b    (a2)
  308.         beq.s    buffset
  309.         move.l    a5,$d0(a0)
  310.         move.w    d4,$d4(a0)
  311.         bra.s    buffset
  312. usebuff1    lea    400(a1),a1
  313.         tst.b    (a2)+
  314.         beq.s    tnspl0b
  315.         move.l    a1,$a0(a0)
  316.         move.w    d4,$a4(a0)
  317. tnspl0b        lea    800(a1),a5
  318.         tst.b    (a2)+
  319.         beq.s    tnspl1b
  320.         move.l    a5,$b0(a0)
  321.         move.w    d4,$b4(a0)
  322. tnspl1b        adda.w    d0,a5
  323.         tst.b    (a2)+
  324.         beq.s    tnspl2b
  325.         move.l    a5,$c0(a0)
  326.         move.w    d4,$c4(a0)
  327. tnspl2b        tst.b    (a2)
  328.         beq.s    buffset
  329.         adda.w    d0,a5
  330.         move.l    a5,$d0(a0)
  331.         move.w    d4,$d4(a0)
  332. buffset        move.w    #1<<7,$9c(a0)
  333.         move.l    #3719168,d3    ;227 * 16384
  334. ; ============== fill buffers ============
  335. startfillb    moveq    #0,d4        ;mask for DMA
  336.         lea    track0hw-DB(a6),a2
  337.         tst.b    trksplit-DB(a6)
  338.         bne.s    tspl0c
  339.         bsr.w    pushregs
  340.         bra.s    tnspl0c
  341. tspl0c        bsr.s    fillbuf
  342.         movea.l    a5,a1
  343. tnspl0c        lea    track1hw-DB(a6),a2
  344.         tst.b    trksplit+1-DB(a6)
  345.         bne.s    tspl1c
  346.         bsr.w    pushregs
  347.         bra.s    tnspl1c
  348. tspl1c        bsr.s    fillbuf
  349.         movea.l    a5,a1
  350. tnspl1c        lea    track2hw-DB(a6),a2
  351.         tst.b    trksplit+2-DB(a6)
  352.         bne.s    tspl2c
  353.         bsr.w    pushregs
  354.         bra.s    tnspl2c
  355. tspl2c        bsr.s    fillbuf
  356.         movea.l    a5,a1
  357. tnspl2c        lea    track3hw-DB(a6),a2
  358.         tst.b    trksplit+3-DB(a6)
  359.         bne.s    tspl3c
  360.         bsr.w    pushregs
  361.         bra.w    do_play8
  362. tspl3c        bsr.s    fillbuf
  363.         bra.w    do_play8
  364. ; =========================================================
  365. ;calculate channel A period
  366. fillbuf:    move.l    d3,d7
  367.         move.w    ac_per(a2),d6
  368.         beq.s    setpzero0
  369.         move.l    d7,d2
  370.         divu     d6,d2
  371.         moveq    #0,d1
  372.         move.w    d2,d1
  373.         add.l    d1,d1
  374.         add.l    d1,d1
  375. ;get channel A addresses
  376.         move.l    ac_end(a2),a5
  377.         move.l    (a2),d0
  378.         beq.s    setpzero0
  379. chA_dfnd    move.l    d0,a3    ;a3 = start address, a5 = end address
  380. ;calc bytes before end
  381.         mulu    currchsize-DB(a6),d2
  382.         clr.w    d2
  383.         swap    d2
  384. ; d2 = # of bytes/fill
  385.         add.l    a3,d2    ;d2 = end position after this fill
  386.         sub.l    a5,d2    ;subtract sample end
  387.         bmi.s    norestart0
  388.         move.l    ac_rest(a2),d0
  389.         beq.s    rst0end
  390.         move.l    d0,(a2)
  391.         move.l    d0,a3
  392.         bra.s    norestart0
  393. rst0end        clr.l    (a2)
  394. setpzero0    lea    zerodata-DB(a6),a3
  395.         moveq    #0,d1
  396. norestart0
  397. ;channel B period
  398.         move.w    SIZE4TRKHW+ac_per(a2),d6
  399.         beq.s    setpzero0b
  400.         divu    d6,d7
  401.         moveq    #0,d2
  402.         move.w    d7,d2
  403.         add.l    d2,d2
  404.         add.l    d2,d2
  405. ;channel B addresses
  406.         move.l    SIZE4TRKHW+ac_end(a2),a5
  407.         move.l    SIZE4TRKHW(a2),d0
  408.         beq.s    setpzero0b
  409.         move.l    d0,a4
  410.         mulu    currchsize-DB(a6),d7
  411.         clr.w    d7
  412.         swap    d7
  413.         add.l    a4,d7
  414.         sub.l    a5,d7
  415.         bmi.s    norestart0b
  416.         move.l    SIZE4TRKHW+ac_rest(a2),d0
  417.         beq.s    rst0endb
  418.         move.l    d0,SIZE4TRKHW(a2)
  419.         move.l    d0,a4
  420.         bra.s    norestart0b
  421. rst0endb    clr.l    SIZE4TRKHW(a2)
  422. setpzero0b    lea    zerodata-DB(a6),a4
  423.         moveq    #0,d2
  424. norestart0b    moveq    #0,d6
  425.         moveq    #0,d7
  426.         move.w    currchszcnt-DB(a6),d5
  427.         lea    800(a1),a5    ;get addr. of next buffer
  428. do8trkmagic
  429.         MAGIC_8TRK    ;20 times..
  430.         MAGIC_8TRK
  431.         MAGIC_8TRK
  432.         MAGIC_8TRK
  433.         MAGIC_8TRK
  434.         MAGIC_8TRK
  435.         MAGIC_8TRK
  436.         MAGIC_8TRK
  437.         MAGIC_8TRK
  438.         MAGIC_8TRK
  439.         MAGIC_8TRK
  440.         MAGIC_8TRK
  441.         MAGIC_8TRK
  442.         MAGIC_8TRK
  443.         MAGIC_8TRK
  444.         MAGIC_8TRK
  445.         MAGIC_8TRK
  446.         MAGIC_8TRK
  447.         MAGIC_8TRK
  448.         MAGIC_8TRK
  449.  
  450.         dbf    d5,do8trkmagic    ;do until cnt zero
  451. end8trkmagic    clr.w    d6
  452.         clr.w    d7
  453.         swap    d6
  454.         swap    d7
  455.         add.l    d6,(a2)
  456.         add.l    d7,SIZE4TRKHW(a2)
  457.         rts
  458.  
  459. _Wait1line:    move.l    d0,-(sp)
  460.         moveq    #$79,d0
  461. wl0:        move.b    $dff007,d1
  462. wl1:        cmp.b    $dff007,d1
  463.         beq.s    wl1
  464.         dbf    d0,wl0
  465.         move.l    (sp)+,d0
  466.         rts
  467. ; ========== this channel is not splitted
  468. pushregs    move.l    ac_rhw(a2),a3        ;address of real hardware
  469.         move.w    ac_per(a2),ac_per(a3)    ;push new period
  470.         move.l    (a2),d0    ;ac_ptr
  471.         beq.s    pregs_nonewp
  472.         move.w    ac_mask(a2),d1
  473.         move.w    d1,$96(a0)    ;stop DMA of curr. channel
  474.         or.w    d1,d4
  475.         clr.l    (a2)+
  476.         move.l    d0,(a3)+    ;to real ac_ptr
  477.         move.w    (a2),(a3)    ;push ac_len
  478. pregs_nonewp    lea    400(a1),a1    ;next buffer
  479.         rts
  480. ; ========== should we start DMA of non-splitted channels?
  481. do_play8    tst.w    d4
  482.         beq.s    do_play8_b    ;no.
  483.         bsr.s    _Wait1line
  484.         bset    #15,d4
  485.         move.w    d4,$96(a0)
  486.         bsr.s    _Wait1line
  487.         lsr.b    #1,d4
  488.         bcc.s    plr_nos8dma0
  489.         move.l    track0hw+ac_rest-DB(a6),$a0(a0)
  490.         move.w    track0hw+ac_end-DB(a6),$a4(a0)
  491. plr_nos8dma0    lsr.b    #1,d4
  492.         bcc.s    plr_nos8dma1
  493.         move.l    track1hw+ac_rest-DB(a6),$b0(a0)
  494.         move.w    track1hw+ac_end-DB(a6),$b4(a0)
  495. plr_nos8dma1    lsr.b    #1,d4
  496.         bcc.s    plr_nos8dma2
  497.         move.l    track2hw+ac_rest-DB(a6),$c0(a0)
  498.         move.w    track2hw+ac_end-DB(a6),$c4(a0)
  499. plr_nos8dma2    lsr.b    #1,d4
  500.         bcc.s    do_play8_b
  501.         move.l    track3hw+ac_rest-DB(a6),$d0(a0)
  502.         move.w    track3hw+ac_end-DB(a6),$d4(a0)
  503. ; ========== player starts here...
  504. do_play8_b    movea.l    _module8-DB(a6),a2
  505.         move.l    a2,d0
  506.         beq.w    plr_exit8
  507.         move.l    mmd_songinfo(a2),a4
  508.         moveq    #0,d3
  509.         lea    mmd_counter(a2),a0
  510.         move.b    (a0),d3
  511.         addq.b    #1,d3
  512.         cmp.b    msng_tempo2(a4),d3
  513.         bge.s    plr_pnewnote8    ;play new note
  514.         move.b    d3,(a0)
  515.         bra.w    nonewnote8    ;do just fx
  516. ; --- new note!! first get address of current block
  517. plr_pnewnote8:    clr.b    (a0)
  518.         tst.w    blkdelay-DB(a6)
  519.         beq.s    plr_noblkdelay8
  520.         subq.w    #1,blkdelay-DB(a6)
  521.         bne.w    nonewnote8
  522. plr_noblkdelay8    move.w    mmd_pblock(a2),d0
  523.         movea.l    mmd_blockarr(a2),a0
  524.         add.w    d0,d0
  525.         add.w    d0,d0
  526.         movea.l    0(a0,d0.w),a1    ;block...
  527.         move.w    mmd_pline(a2),d0
  528.     IFNE    PLAYMMD0
  529.         cmp.b    #'1',3(a2)    ;check ID type
  530.         beq.s    plr_mmd1_0
  531.         move.w    d0,d1
  532.         add.w    d0,d0
  533.         add.w    d1,d0        ;d0 = d0 * 3
  534.         clr.l    numtracks-DB(a6)
  535.         move.b    (a1)+,numtracks+1-DB(a6)
  536.         move.b    (a1),numlines+1-DB(a6)
  537.         mulu    numtracks-DB(a6),d0
  538.         pea    1(a1,d0.w)
  539.         bra.s    plr_begloop
  540. plr_mmd1_0
  541.     ENDC
  542.         add.w    d0,d0
  543.         add.w    d0,d0        ;d0 = d0 * 4
  544.         mulu    (a1),d0        ;numtracks * d0
  545.         pea    8(a1,d0.l)    ;address of the current note
  546.         move.w    (a1)+,numtracks-DB(a6)
  547.         move.w    (a1),numlines-DB(a6)
  548. plr_begloop    moveq    #0,d7        ;number of track
  549.         moveq    #0,d4
  550.         pea    trackdata8-DB(a6)
  551. plr_loop08    moveq    #0,d5
  552.         cmp.w    #8,d7
  553.         bge.w    plr_endloop08
  554.         move.l    (sp),a1
  555.         movea.l    (a1)+,a5    ;get address of this track's struct
  556.         move.l    a1,(sp)
  557. ; ---------------- get the note numbers
  558.         moveq    #0,d3
  559.         move.l    4(sp),a1
  560.     IFNE    PLAYMMD0
  561.         cmp.b    #'1',3(a2)
  562.         beq.s    plr_mmd1_1
  563.         move.b    (a1)+,d5
  564.         move.b    (a1)+,d6
  565.         move.b    (a1)+,trk_cmdqual(a5)
  566.         move.b    d6,d3
  567.         and.w    #$0F,d6
  568.         lsr.b    #4,d3
  569.         bclr    #7,d5
  570.         beq.s    plr_bseti4
  571.         bset    #4,d3
  572. plr_bseti4    bclr    #6,d5
  573.         beq.s    plr_bseti5
  574.         bset    #5,d3
  575. plr_bseti5    bra.s    plr_nngok
  576. plr_mmd1_1
  577.     ENDC
  578.         move.b    (a1)+,d5    ;get the number of this note
  579.         bpl.s    plr_nothinote
  580.         moveq    #0,d5
  581. plr_nothinote    move.b    (a1)+,d3    ;instrument number
  582.         move.b    (a1)+,d6    ;cmd number
  583.         and.w    #$1F,d6        ;recognize only cmds 00 - 1F
  584.         move.b    (a1)+,trk_cmdqual(a5)    ;databyte (qualifier)
  585. plr_nngok    move.l    a1,4(sp)
  586. ; ---------------- check if there's an instrument number
  587.         and.w    #$3F,d3
  588.         beq.s    noinstnum8
  589. ; ---------------- finally, save the number
  590.         subq.b    #1,d3
  591.         move.b    d3,trk_previnstr(a5) ;remember instr. number!
  592.     IFNE    HOLD
  593.         lea    holdvals-DB(a6),a0
  594.         adda.w    d3,a0
  595.         move.b    (a0),trk_inithold(a5)
  596.         move.b    63(a0),trk_finetune(a5)
  597.     ENDC
  598.         asl.w    #3,d3
  599.         lea    0(a4,d3.w),a3    ;a3 contains now address of it
  600.         move.l    a3,trk_previnstra(a5)
  601.         moveq    #0,d0
  602. ; ---------------- set volume to 64
  603.         movea.l    trk_audioaddr(a5),a0
  604.         movea.l    ac_vol(a0),a0    ;ptr to volume hardware register
  605.         moveq    #64,d0
  606.         move.b    d0,(a0)
  607.         move.b    d0,trk_prevvol(a5)
  608. ; ---------------- remember transpose
  609.         move.b    inst_strans(a3),trk_stransp(a5)
  610.         clr.w    trk_soffset(a5)        ;sample offset
  611. ; ---------------- check the commands
  612. noinstnum8    move.b    d6,trk_cmd(a5)    ;save the effect number
  613.         beq.w    fx8    ;no effect
  614.         move.b    trk_cmdqual(a5),d4    ;get qualifier...
  615.         add.b    d6,d6    ;* 2
  616.         move.w    f_table8(pc,d6.w),d0
  617.         jmp    fst8(pc,d0.w)
  618. f_table8    dc.w    fx8-fst8,fx8-fst8,fx8-fst8,f_038-fst8,fx8-fst8,fx8-fst8,fx8-fst8,fx8-fst8
  619.         dc.w    f_088-fst8,f_098-fst8,fx8-fst8,f_0b8-fst8,f_0c8-fst8,fx8-fst8,fx8-fst8,f_0f8-fst8
  620.         dc.w    fx8-fst8,fx8-fst8,fx8-fst8,fx8-fst8,fx8-fst8,f_158-fst8,f_168-fst8,fx8-fst8
  621.         dc.w    fx8-fst8,f_198-fst8,fx8-fst8,fx8-fst8,fx8-fst8,f_1d8-fst8,fx8-fst8,f_1f8-fst8
  622. fst8
  623. ; ---------------- tempo (F)
  624. f_0f8        tst.b    d4        ;test effect qual..
  625.         beq.s    fx0fchgblck8    ;if effect qualifier (last 2 #'s)..
  626.         cmp.b    #$f0,d4        ;..is zero, go to next block
  627.         bhi.s    fx0fspecial8
  628.         moveq    #0,d0
  629.         move.b    d4,d0
  630.         bsr.w    _SetTempo
  631.         bra.w    fx8
  632. ; ---------------- no, it was FFx
  633. fx0fspecial8    cmp.b    #$f2,d4
  634.         bne.s    isfxfe8
  635. ; ---------------- it was FF2, nothing to do now
  636. f_1f8        move.b    d5,(a5)    ; save the note number
  637.         moveq    #0,d5    ; clear the number for awhile
  638.     IFNE    HOLD
  639.         move.b    trk_inithold(a5),trk_noteoffcnt(a5) ;initialize hold
  640.         bne.w    plr_endloop08
  641.         st    trk_noteoffcnt(a5)
  642.     ENDC
  643.         bra.w    plr_endloop08
  644. isfxfe8        cmp.b    #$fe,d4
  645.         bne.s    notcmdfe8
  646. ; ---------------- it was FFE, stop playing
  647.         clr.w    mmd_pstate(a2)
  648.         bra.w    fx8
  649. notcmdfe8    cmp.b    #$fd,d4 ;change period
  650.         bne.s    isfxff8
  651. ; ---------------- FFD, change the period, don't replay the note
  652.         cmp.w    #8,d7
  653.         bge.w    fx8
  654.         movea.l    trk_periodtbl(a5),a0    ;period table
  655.         subq.b    #1,d5
  656.         bmi.w    plr_endloop08    ;under zero, do nothing
  657.         add.b    d5,d5
  658.         move.w    0(a0,d5.w),trk_prevper(a5) ;get & push the period
  659.         moveq    #0,d5        ;don't retrigger note
  660.         bra.w    fx8    ;done!!
  661. isfxff8        cmp.b    #$ff,d4        ;note off??
  662.         bne.w    fx8
  663.         move.w    d7,d0
  664.         bsr.w    _ChannelO8
  665.         bra.w    fx8
  666. ; ---------------- F00
  667. fx0fchgblck8    move.b    #1,nextblock-DB(a6)
  668.         bra.w    fx8
  669. ; ---------------- change volume
  670. f_0c8        btst    #4,msng_flags(a4)    ;look at flags
  671.         bne.s    volhex8
  672.         move.b    d4,d1        ;get again
  673.         lsr.b    #4,d4        ;get number from left
  674.         mulu    #10,d4        ;number of tens
  675.         and.b    #$0f,d1        ;this time don't get tens
  676.         add.b    d1,d4        ;add them
  677. volhex8        cmp.b    #64,d4
  678.         bhi.s    go_nocmd8
  679.         movea.l    trk_audioaddr(a5),a0
  680.         movea.l    ac_vol(a0),a0
  681.         move.b    d4,(a0)
  682. go_nocmd8    bra.w    fx8
  683. ; ---------------- tempo2 change??
  684. f_098
  685.     IFNE    CHECK
  686.         and.b    #$1F,d4
  687.         bne.s    fx9chk8
  688.         moveq    #$20,d4
  689.     ENDC
  690. fx9chk8        move.b    d4,msng_tempo2(a4)
  691.         bra    fx8
  692. ; ---------------- finetune
  693. f_158
  694.     IFNE    CHECK
  695.         cmp.b    #7,d4
  696.         bgt    fx8
  697.         cmp.b    #-8,d4
  698.         blt    fx8
  699.     ENDC
  700.         move.b    d4,trk_finetune(a5)
  701.         bra    fx8
  702. ; ---------------- repeat loop
  703. f_168        tst.b    d4
  704.         bne.s    plr_dorpt8
  705.         move.w    mmd_pline(a2),rptline-DB(a6)
  706.         bra    fx8
  707. plr_dorpt8    tst.w    rptcounter-DB(a6)
  708.         beq.s    plr_newrpt8
  709.         subq.w    #1,rptcounter-DB(a6)
  710.         beq.s    fx8
  711.         bra.s    plr_setrptline8
  712. plr_newrpt8    move.b    d4,rptcounter+1-DB(a6)
  713. plr_setrptline8    move.w    rptline-DB(a6),d0
  714.         addq.w    #1,d0
  715.         move.w    d0,nextblockline-DB(a6)
  716.         bra.s    fx8
  717. ; ---------------- note off time set??
  718. f_088
  719.     IFNE    HOLD
  720.         move.b    d4,d0
  721.         and.b    #$0f,d4
  722.         move.b    d4,trk_inithold(a5)    ;right = hold
  723.     ENDC
  724.         bra.s    fx8
  725. ; ---------------- sample begin offset
  726. f_198        tst.b    d4
  727.         beq.s    fx8
  728.         lsl.w    #8,d4
  729.         move.w    d4,trk_soffset(a5)
  730.         bra.s    fx8
  731. ; ---------------- cmd Bxx, "position jump"
  732. f_0b8
  733.     IFNE    CHECK
  734.         cmp.w    msng_songlen(a4),d4    ;test the song length
  735.         bhi.s    fx8
  736.     ENDC
  737.         move.w    d4,mmd_pseqnum(a2)
  738.         st    nextblock-DB(a6)
  739.         bra.s    fx8
  740. ; ---------------- cmd 1Dxx, jump to next seq, line # specified
  741. f_1d8        move.w    #$1ff,nextblock-DB(a6)
  742.         addq.w    #1,d4
  743.         move.w    d4,nextblockline-DB(a6)
  744.         bra.s    fx8
  745. ; ---------------- try portamento (3)
  746. f_038        subq.b    #1,d5
  747.         bmi.s    plr_setfx3spd8
  748. plr_fx3note8    movea.l    trk_periodtbl(a5),a0
  749.         add.b    msng_playtransp(a4),d5    ;play transpose
  750.         add.b    trk_stransp(a5),d5 ;and instrument transpose
  751.         bmi.s    plr_endloop08    ;again.. too low
  752.         add.w    d5,d5
  753.         move.w    0(a0,d5.w),trk_porttrgper(a5) ;period of this note is the target
  754. plr_setfx3spd8    tst.b    d4        ;qual?
  755.         beq.s    plr_endloop08    ;0 -> do nothing
  756.         move.b    d4,trk_prevportspd(a5)    ;remember size
  757.         bra.s    plr_endloop08
  758. ; ---------------- everything is checked now: play or not to play??
  759. fx8        tst.b    d5    ;Now we'll check if we have to play a note
  760.         beq.s    plr_endloop08    ;no.
  761. ; ---------------- we decided to play
  762.         move.b    d5,(a5)
  763.         move.w    d5,d1
  764.         moveq    #0,d3
  765.         move.b    trk_previnstr(a5),d3    ;instr #
  766.         movea.l    trk_previnstra(a5),a3    ;instr data address
  767.     IFNE    HOLD
  768.         move.b    trk_inithold(a5),trk_noteoffcnt(a5)
  769.         bne.s    plr_nohold8
  770.         st    trk_noteoffcnt(a5)
  771.     ENDC
  772. ; ---------------- and finally:
  773. plr_nohold8    bsr    _PlayNote8
  774. ; ---------------- end of loop: handle next track, or quit
  775. plr_endloop08    addq.b    #1,d7
  776.         cmp.w    numtracks-DB(a6),d7
  777.         blt.w    plr_loop08
  778.         addq.l    #8,sp        ;trackdataptrs
  779.         lea    trackdata8-DB(a6),a5
  780. ; and advance song pointers
  781.         lea    nextblock-DB(a6),a3
  782.         move.w    nextblockline-DB(a6),d1
  783.         beq.s    plr_advlinenum
  784.         clr.w    nextblockline-DB(a6)
  785.         subq.w    #1,d1
  786.         bra.s    plr_linenumset
  787. plr_advlinenum    move.w    mmd_pline(a2),d1    ;get current line #
  788.         addq.w    #1,d1            ;advance line number
  789. plr_linenumset    cmp.w    numlines-DB(a6),d1     ;advance block?
  790.         bhi.s    plr_chgblock        ;yes.
  791.         tst.b    (a3)            ;command F00/1Dxx?
  792.         beq.s    plr_nochgblock        ;no, don't change block
  793. plr_chgblock    tst.b    nxtnoclrln-DB(a6)
  794.         bne.s    plr_noclrln
  795.         moveq    #0,d1            ;clear line number
  796. plr_noclrln    tst.w    mmd_pstate(a2)        ;play block or play song
  797.         bpl.s    plr_nonewseq        ;play block only...
  798.         move.w    mmd_pseqnum(a2),d0    ;get play sequence number
  799.         tst.b    (a3)
  800.         bmi.s    plr_noadvseq        ;Bxx sets nextblock to -1
  801.         addq.w    #1,d0            ;advance sequence number
  802. plr_noadvseq    cmp.w    msng_songlen(a4),d0    ;is this the highest seq number??
  803.         blt.s    plr_notagain        ;no.
  804.         moveq    #0,d0            ;yes: restart song
  805. plr_notagain    move.b    d0,mmd_pseqnum+1(a2)    ;remember new playseq-#
  806.         lea    msng_playseq(a4),a0    ;offset of sequence table
  807.         move.b    0(a0,d0.w),d0        ;get number of the block
  808.     IFNE    CHECK
  809.         cmp.w    msng_numblocks(a4),d0    ;beyond last block??
  810.         blt.s    plr_nolstblk        ;no..
  811.         moveq    #0,d0            ;play block 0
  812.     ENDC
  813. plr_nolstblk    move.b    d0,mmd_pblock+1(a2)    ;store block number
  814. plr_nonewseq    clr.w    (a3)             ;clear this if F00 set it
  815. plr_nochgblock    move.w    d1,mmd_pline(a2)    ;set new line number
  816.  
  817.     IFNE    HOLD
  818.         lea    trackdata8-DB(a6),a5
  819.         movea.l    mmd_blockarr(a2),a0
  820.         move.w    mmd_pblock(a2),d0
  821.         add.w    d0,d0
  822.         add.w    d0,d0
  823.         movea.l    0(a0,d0.w),a1    ;block...
  824.         move.w    mmd_pline(a2),d0
  825.         move.b    msng_tempo2(a4),d3    ;interrupts/note
  826.     IFNE    PLAYMMD0
  827.         cmp.b    #'1',3(a2)
  828.         beq.s    plr_mmd1_2
  829.         move.b    (a1),d7            ;# of tracks
  830.         move.w    d0,d1
  831.         add.w    d0,d0    ;d0 * 2
  832.         add.w    d1,d0    ;+ d0 = d0 * 3
  833.         mulu    d7,d0
  834.         lea    2(a1,d0.w),a3
  835.         subq.b    #1,d7
  836. plr_chkholdb    movea.l    (a5)+,a1        ;track data
  837.         tst.b    trk_noteoffcnt(a1)    ;hold??
  838.         bmi.s    plr_holdendb        ;no.
  839.         move.b    (a3),d1            ;get the 1st byte..
  840.         bne.s    plr_hold1b
  841.         move.b    1(a3),d1
  842.         and.b    #$f0,d1
  843.         beq.s    plr_holdendb        ;don't hold
  844.         bra.s    plr_hold2b
  845. plr_hold1b    and.b    #$3f,d1            ;note??
  846.         beq.s    plr_hold2b        ;no, cont hold..
  847.         move.b    1(a3),d1
  848.         and.b    #$0f,d1            ;get cmd
  849.         subq.b    #3,d1            ;is there command 3 (slide)
  850.         bne.s    plr_holdendb        ;no -> end holding
  851. plr_hold2b    add.b    d3,trk_noteoffcnt(a1)    ;continue holding...
  852. plr_holdendb    addq.l    #3,a3        ;next note
  853.         dbf    d7,plr_chkholdb
  854.         bra.s    nonewnote8
  855. plr_mmd1_2
  856.     ENDC
  857.         move.w    (a1),d7        ;# of tracks
  858.         add.w    d0,d0
  859.         add.w    d0,d0    ;d0 = d0 * 4
  860.         mulu    d7,d0
  861.         lea    8(a1,d0.l),a3
  862.         subq.b    #1,d7
  863. plr_chkhold    movea.l    (a5)+,a1        ;track data
  864.         tst.b    trk_noteoffcnt(a1)    ;hold??
  865.         bmi.s    plr_holdend        ;no.
  866.         move.b    (a3),d1            ;get the 1st byte..
  867.         bne.s    plr_hold1
  868.         move.b    1(a3),d0
  869.         and.b    #$3F,d0
  870.         beq.s    plr_holdend        ;don't hold
  871.         bra.s    plr_hold2
  872. plr_hold1    and.b    #$7f,d1            ;note??
  873.         beq.s    plr_hold2        ;no, cont hold..
  874.         move.b    2(a3),d1
  875.         subq.b    #3,d1            ;is there command 3 (slide)
  876.         bne.s    plr_holdend        ;no -> end holding
  877. plr_hold2    add.b    d3,trk_noteoffcnt(a1)    ;continue holding...
  878. plr_holdend    addq.l    #4,a3        ;next note
  879.         dbf    d7,plr_chkhold
  880.     ENDC
  881. nonewnote8    moveq    #0,d3
  882.         move.b    mmd_counter(a2),d3
  883. plr_fxtime    lea    trackdata8-DB(a6),a3
  884.         moveq    #0,d7    ;clear track count
  885. plr_loop1:    movea.l    (a3)+,a5
  886.         cmp.w    #8,d7
  887.         bge.w    endl
  888.         moveq    #0,d4
  889.         moveq    #0,d5
  890.         moveq    #0,d6
  891.         move.b    trk_cmd(a5),d6    ;get the fx number
  892.         move.b    trk_cmdqual(a5),d4    ;and the last 2 #'s
  893.     IFNE    HOLD
  894.         tst.b    trk_noteoffcnt(a5)
  895.         bmi.s    plr_nofade
  896.         subq.b    #1,trk_noteoffcnt(a5)
  897.         bpl.s    plr_nofade
  898.         move.w    d7,d0
  899.         bsr.w    _ChannelO8
  900. plr_nofade
  901.     ENDC
  902.         add.b    d6,d6    ;* 2
  903.         move.w    fx_table(pc,d6.w),d0
  904.         jmp    fxs(pc,d0.w)
  905. fx_table    dc.w    fx_00-fxs,fx_01-fxs,fx_02-fxs,fx_03-fxs,fx_04-fxs
  906.         dc.w    fx_05-fxs,fx_06-fxs,fx_07-fxs,fx_xx-fxs,fx_xx-fxs
  907.         dc.w    fx_0a-fxs,fx_xx-fxs,endl-fxs,fx_0d-fxs,fx_xx-fxs
  908.         dc.w    fx_0f-fxs
  909.         dc.w    fx_xx-fxs,fx_11-fxs,fx_12-fxs,fx_13-fxs,fx_14-fxs
  910.         dc.w    fx_xx-fxs,fx_xx-fxs,fx_xx-fxs,fx_18-fxs,fx_xx-fxs
  911.         dc.w    fx_1a-fxs,fx_1b-fxs,fx_xx-fxs,fx_xx-fxs,fx_1e-fxs
  912.         dc.w    fx_1f-fxs
  913. fxs:
  914. ;    **************************************** Effect 01 ******
  915. fx_01:        tst.b    d3
  916.         bne.s    fx_01nocnt0
  917.         btst    #5,msng_flags(a4)    ;FLAG_STSLIDE??
  918.         bne    endl
  919. fx_01nocnt0    sub.w    d4,trk_prevper(a5)
  920.         move.w    trk_prevper(a5),d5
  921.         cmp.w    #113,d5
  922.         bge    plr_newper
  923.         move.w    #113,d5
  924.         move.w    d5,trk_prevper(a5)
  925.         bra    plr_newper
  926. ;    **************************************** Effect 11 ******
  927. fx_11        tst.b    d3
  928.         bne    fx_xx
  929.         sub.w    d4,trk_prevper(a5)
  930.         move.w    trk_prevper(a5),d5
  931.         bra    plr_newper
  932. ;    **************************************** Effect 02 ******
  933. fx_02:        tst.b    d3
  934.         bne.s    fx_02nocnt0
  935.         btst    #5,msng_flags(a4)
  936.         bne    endl
  937. fx_02nocnt0    add.w    d4,trk_prevper(a5)
  938.         move.w    trk_prevper(a5),d5
  939.         bra.w    plr_newper
  940. ;    **************************************** Effect 12 ******
  941. fx_12        tst.b    d3
  942.         bne    fx_xx
  943.         add.w    d4,trk_prevper(a5)
  944.         move.w    trk_prevper(a5),d5
  945.         bra    plr_newper
  946. ;    **************************************** Effect 00 ******
  947. fx_00:        tst.b    d4    ;both fxqualifiers are 0s: no arpeggio
  948.         beq.w    fx_xx
  949.         move.l    d3,d0
  950.         divu    #3,d0
  951.         swap    d0
  952.         tst.w    d0
  953.         bne.s    fx_arp12
  954.         and.b    #$0f,d4
  955.         add.b    (a5),d4
  956.         bra.s    fx_doarp
  957. fx_arp12:    subq.b    #1,d0
  958.         bne.s    fx_arp2
  959.         lsr.b    #4,d4
  960.         add.b    (a5),d4
  961.         bra.s    fx_doarp
  962. fx_arp2:    move.b    (a5),d4
  963. fx_doarp:    subq.b    #1,d4        ;-1 to make it 0 - 127
  964.         add.b    msng_playtransp(a4),d4    ;add play transpose
  965.         add.b    trk_stransp(a5),d4    ;add instrument transpose
  966.         add.b    d4,d4
  967.         movea.l    trk_periodtbl(a5),a1
  968.         move.w    0(a1,d4.w),d5
  969.         bra.w    plr_newper
  970. ;    **************************************** Effect 04 ******
  971. fx_14        move.b    #6,trk_vibshift(a5)
  972.         bra.s    vib_cont
  973. fx_04        move.b    #5,trk_vibshift(a5)
  974. vib_cont    tst.b    d3
  975.         bne.s    nonvib
  976.         move.b    d4,d1
  977.         beq.s    nonvib
  978.         and.w    #$0f,d1
  979.         beq.s    plr_chgvibspd
  980.         move.w    d1,trk_vibrsz(a5)
  981. plr_chgvibspd:    and.b    #$f0,d4
  982.         beq.s    nonvib
  983.         lsr.b    #3,d4
  984.         and.b    #$3e,d4
  985.         move.b    d4,trk_vibrspd(a5)
  986. nonvib:        move.b    trk_vibroffs(a5),d0
  987.         lsr.b    #2,d0
  988.         and.w    #$1f,d0
  989.         moveq    #0,d1
  990.         move.b    sinetable(pc,d0.w),d5
  991.         ext.w    d5
  992.         muls    trk_vibrsz(a5),d5
  993.         move.b    trk_vibshift(a5),d1
  994.         asr.w    d1,d5
  995.         add.w    trk_prevper(a5),d5
  996.         move.b    trk_vibrspd(a5),d0
  997.         add.b    d0,trk_vibroffs(a5)
  998.         bra.w    plr_newper
  999. sinetable:    dc.b    0,25,49,71,90,106,117,125,127,125,117,106,90,71,49
  1000.         dc.b    25,0,-25,-49,-71,-90,-106,-117,-125,-127,-125,-117
  1001.         dc.b    -106,-90,-71,-49,-25,0
  1002.         even
  1003. ;    **************************************** Effect 06 ******
  1004. fx_06:        tst.b    d3
  1005.         bne.s    fx_06nocnt0
  1006.         btst    #5,msng_flags(a4)
  1007.         bne    newvals
  1008. fx_06nocnt0    bsr.s    plr_volslide        ;Volume slide
  1009.         bra.s    nonvib            ;+ Vibrato
  1010. ;    **************************************** Effect 07 ******
  1011. fx_07        tst.b    d3
  1012.         bne.s    nontre
  1013.         move.b    d4,d1
  1014.         beq.s    nontre
  1015.         and.w    #$0f,d1
  1016.         beq.s    plr_chgtrespd
  1017.         move.w    d1,trk_tremsz(a5)
  1018. plr_chgtrespd    and.b    #$f0,d4
  1019.         beq.s    nonvib
  1020.         lsr.b    #2,d4
  1021.         and.b    #$3e,d4
  1022.         move.b    d4,trk_tremspd(a5)
  1023. nontre        move.b    trk_tremoffs(a5),d0
  1024.         lsr.b    #3,d0
  1025.         and.w    #$1f,d0
  1026.         moveq    #0,d1
  1027.         move.b    sinetable(pc,d0.w),d5
  1028.         ext.w    d5
  1029.         muls    trk_tremsz(a5),d5
  1030.         asr.w    #7,d5
  1031.         move.b    trk_tremspd(a5),d0
  1032.         add.b    d0,trk_tremoffs(a5)
  1033.         move.b    trk_prevvol(a5),d1
  1034.         add.b    d5,d1
  1035.         bpl.s    tre_pos
  1036.         moveq    #0,d1
  1037. tre_pos        cmp.b    #64,d1
  1038.         ble.s    tre_no2hi
  1039.         moveq    #64,d1
  1040. tre_no2hi    move.b    d1,trk_tempvol(a5)
  1041.         bra.w    newvals
  1042. ;    **************************************** Effect 0D/0A ***
  1043. fx_0a:
  1044. fx_0d:        tst.b    d3
  1045.         bne.s    fx_0dnocnt0
  1046.         btst    #5,msng_flags(a4)
  1047.         bne    newvals
  1048. fx_0dnocnt0    bsr.s    plr_volslide
  1049.         bra    newvals
  1050. ;    ********* VOLUME SLIDE FUNCTION *************************
  1051. plr_volslide    move.b    d4,d0
  1052.         moveq    #0,d1
  1053.         move.b    trk_prevvol(a5),d1 ;move previous vol to d1
  1054.         and.b    #$f0,d0
  1055.         bne.s    crescendo
  1056.         sub.b    d4,d1    ;sub from prev. vol
  1057. voltest0    bpl.s    novolover64
  1058.         moveq    #0,d1    ;volumes under zero not accepted!!!
  1059.         bra.s    novolover64
  1060. crescendo:    lsr.b    #4,d0
  1061.         add.b    d0,d1
  1062. voltest        cmp.b    #64,d1
  1063.         ble.s    novolover64
  1064.         moveq    #64,d1
  1065. novolover64    move.b    d1,trk_prevvol(a5)
  1066.         movea.l    trk_audioaddr(a5),a0
  1067.         movea.l    ac_vol(a0),a0
  1068.         move.b    d1,(a0)
  1069.         rts
  1070. ;    **************************************** Effect 1A ******
  1071. fx_1a        tst.b    d3
  1072.         bne    fx_xx
  1073.         move.b    trk_prevvol(a5),d1
  1074.         add.b    d4,d1
  1075.         bsr.s    voltest
  1076.         bra    newvals
  1077. ;    **************************************** Effect 1B ******
  1078. fx_1b        tst.b    d3
  1079.         bne    fx_xx
  1080.         move.b    trk_prevvol(a5),d1
  1081.         sub.b    d4,d1
  1082.         bsr.s    voltest0
  1083.         bra    newvals
  1084. ;    **************************************** Effect 05 ******
  1085. fx_05:        tst.b    d3
  1086.         bne.s    fx_05nocnt0
  1087.         btst    #5,msng_flags(a4)
  1088.         bne    newvals
  1089. fx_05nocnt0    bsr.s    plr_volslide        ;Volume slide
  1090.         bra.s    fx_03nocnt0
  1091. ;    **************************************** Effect 03 ******
  1092. fx_03:        tst.b    d3
  1093.         bne.s    fx_03nocnt0
  1094.         btst    #5,msng_flags(a4)
  1095.         bne    newvals
  1096. fx_03nocnt0    move.w    trk_porttrgper(a5),d0    ;d0 = target period
  1097.         beq.w    newvals    ;no target period specified
  1098.         move.w    trk_prevper(a5),d1    ;d1 = curr. period
  1099.         move.b    trk_prevportspd(a5),d4    ;get prev. speed
  1100.         cmp.w    d0,d1
  1101.         bhi.s    subper    ;curr. period > target period
  1102.         add.w    d4,d1    ;add the period
  1103.         cmp.w    d0,d1
  1104.         bge.s    targreached
  1105.         bra.s    targnreach
  1106. subper:        sub.w    d4,d1    ;subtract
  1107.         cmp.w    d0,d1    ;compare current period to target period
  1108.         bgt.s    targnreach
  1109. targreached:    move.w    trk_porttrgper(a5),d1 ;eventually push target period
  1110.         clr.w    trk_porttrgper(a5) ;now we can forget everything
  1111. targnreach:    move.w    d1,trk_prevper(a5)
  1112.         move.w    d1,d5
  1113.         bra.s    plr_newper
  1114. ;    **************************************** Effect 13 ******
  1115. fx_13:        move.w    trk_prevper(a5),d5 ;this is very simple: get the old period
  1116.         cmp.b    #3,d3        ;and..
  1117.         bge.s    plr_newper    ;if counter < 3
  1118.         sub.w    d4,d5    ;subtract effect qualifier
  1119.         bra.s    plr_newper
  1120. ;    **************************************** Effect 1E ******
  1121. fx_1e        tst.w    blkdelay-DB(a6)
  1122.         bne.s    fx_xx
  1123.         addq.w    #1,d4
  1124.         move.w    d4,blkdelay-DB(a6)
  1125.         bra.s    fx_xx
  1126. ;    **************************************** Effect 18 ******
  1127. fx_18        cmp.b    d4,d3
  1128.         bne    fx_xx
  1129.         clr.w    trk_prevper(a5)
  1130.         bra.s    endl
  1131. ;    **************************************** Effect 1F ******
  1132. fx_1f        move.b    d4,d1
  1133.         lsr.b    #4,d4        ;note delay
  1134.         beq.s    nonotedelay
  1135.         cmp.b    d4,d3        ;compare to counter
  1136.         blt.s    fx_xx        ;tick not reached
  1137.         bne.s    nonotedelay
  1138.         bsr    playfxnote    ;trigger note
  1139. nonotedelay    and.w    #$0f,d1        ;retrig?
  1140.         beq.s    fx_xx
  1141.         moveq    #0,d0
  1142.         move.b    d3,d0
  1143.         divu    d1,d0
  1144.         swap    d0        ;get modulo of counter/tick
  1145.         tst.w    d0
  1146.         bne.s    fx_xx
  1147.         bsr.s    playfxnote    ;retrigger
  1148.         bra.s    fx_xx
  1149. ;    **************************************** Effect 0F ******
  1150. fx_0f:        bsr.s    cmd_F
  1151. ;    *********************************************************
  1152. fx_xx:
  1153. newvals:    move.w    trk_prevper(a5),d5
  1154. plr_newper
  1155. plr_tmpper    movea.l    trk_audioaddr(a5),a1    ;get channel address
  1156.         move.w    d5,ac_per(a1)        ;push period
  1157. endl:        addq.b    #1,d7    ;increment channel number
  1158.         cmp.w    numtracks-DB(a6),d7    ;all channels done???
  1159.         blt.w    plr_loop1    ;not yet!!!
  1160.  
  1161. plr_exit8    movem.l    (sp)+,d2-d7/a2-a5
  1162.         moveq    #1,d0
  1163.         rts
  1164.  
  1165. cmd_F        cmp.b    #$f1,d4
  1166.         bne.s    no0ff1
  1167.         cmp.b    #3,d3
  1168.         beq.s    playfxnote
  1169.         rts
  1170. no0ff1:        cmp.b    #$f2,d4
  1171.         bne.s    no0ff2
  1172.         cmp.b    #3,d3
  1173.         beq.s    playfxnote
  1174.         rts
  1175. no0ff2:        cmp.b    #$f3,d4
  1176.         bne.s    no0ff3
  1177.         move.b    d3,d0
  1178.         and.b    #2+4,d0        ;is 2 or 4
  1179.         beq.s    cF_rts
  1180. playfxnote:    moveq    #0,d1
  1181.         move.b    (a5),d1        ;get note # of previous note
  1182.         beq.s    cF_rts
  1183.         move.b    trk_noteoffcnt(a5),d0    ;get hold counter
  1184.         bmi.s    pfxn_nohold        ;no hold, or hold over
  1185.         add.b    d3,d0            ;increase by counter val
  1186.         bra.s    pfxn_hold
  1187. pfxn_nohold    move.b    trk_inithold(a5),d0    ;get initial hold
  1188.         bne.s    pfxn_hold
  1189.         st    d0
  1190. pfxn_hold    move.b    d0,trk_noteoffcnt(a5)
  1191.         move.l    d3,-(sp)
  1192.         moveq    #0,d3
  1193.         move.b    trk_previnstr(a5),d3    ;and prev. sample #
  1194.         move.l    a3,-(sp)
  1195.         movea.l    trk_previnstra(a5),a3
  1196.         bsr    _PlayNote8
  1197.         movea.l    (sp)+,a3
  1198.         move.l    (sp)+,d3
  1199.         rts
  1200. no0ff3:        cmp.b    #$f8,d4        ;f8 = filter off
  1201.         beq.s    plr_filteroff
  1202.         cmp.b    #$f9,d4        ;f9 = filter on
  1203.         bne.s    cF_rts
  1204.         bclr    #1,$bfe001
  1205.         rts
  1206. plr_filteroff:    bset    #1,$bfe001
  1207. cF_rts        rts
  1208.  
  1209. _SetTempo:    move.l    _module8-DB(a6),d1
  1210.         beq.s    ST_x
  1211.         movea.l    d1,a0
  1212.         movea.l    mmd_songinfo(a0),a0
  1213.         move.w    d0,msng_deftempo(a0)
  1214.         tst.w    d0
  1215.         ble.s    ST_maxszcnt
  1216.         cmp.w    #9,d0
  1217.         bls.s    ST_nodef8tempo
  1218. ST_maxszcnt    moveq    #10,d0
  1219. ST_nodef8tempo    add.b    #9,d0
  1220.         move.b    d0,currchszcnt-DB+1(a6)
  1221.         lea    eightchsizes-10-DB(a6),a0
  1222.         move.b    0(a0,d0.w),d0    ;get buffersize / 2
  1223.         move.w    d0,currchsize2-DB(a6)
  1224.         asl.w    #3,d0        ;get buffersize * 4
  1225.         move.w    d0,currchsize-DB(a6)
  1226. ST_x        rts
  1227.  
  1228. _Rem8chan:    move.l    a6,-(sp)
  1229.         lea    DB,a6
  1230.         move.b    eightrkon-DB(a6),d0
  1231.         beq.s    no8init
  1232.         clr.b    eightrkon-DB(a6)
  1233.         move.w    #1<<7,$dff09a
  1234.         moveq    #7,d0
  1235.         move.l    prevaud-DB(a6),d0
  1236.         beq.s    no8init
  1237.         move.l    d0,a1
  1238.         move.l    4,a6
  1239.         jsr    -$a2(a6)
  1240. no8init        move.l    (sp)+,a6
  1241.         rts
  1242.  
  1243. _End8Play:    tst.b    play8
  1244.         beq.s    noend8play
  1245.         move.w    #1<<7,$dff09a
  1246.         move.w    #$F,$dff096
  1247.         clr.b    play8
  1248. noend8play    rts
  1249.  
  1250. ; *************************************************************************
  1251. ; *************************************************************************
  1252. ; ***********          P U B L I C   F U N C T I O N S          ***********
  1253. ; *************************************************************************
  1254. ; *************************************************************************
  1255.  
  1256.         xdef    _PlayModule8
  1257.         xdef    _InitPlayer8,_RemPlayer8,_StopPlayer8
  1258.         xdef    _ContModule8
  1259.  
  1260. ; *************************************************************************
  1261. ; InitModule8(a0 = module) -- extract expansion data etc.. from the module
  1262. ; *************************************************************************
  1263.  
  1264. _InitModule8:    movem.l    a2-a3/d2,-(sp)
  1265.         move.l    a0,d0
  1266.         beq.s    IM_exit            ;0 => xit
  1267.         lea    holdvals-DB(a6),a2
  1268.         move.l    mmd_expdata(a0),d0    ;expdata...
  1269.         beq.s    IM_clrhlddec        ;none here
  1270.         move.l    d0,a1
  1271.         move.l    4(a1),d0        ;exp_smp
  1272.         beq.s    IM_clrhlddec    ;again.. nothing
  1273.         move.l    d0,a0        ;InstrExt...
  1274.         move.w    8(a1),d2    ;# of entries
  1275.         beq.s    IM_clrhlddec
  1276.         subq.w    #1,d2        ;- 1 (for dbf)
  1277.         move.w    10(a1),d0    ;entry size
  1278. IM_loop1    cmp.w    #3,d0
  1279.         ble.s    IM_noftune
  1280.         move.b    3(a0),63(a2)
  1281. IM_noftune    move.b    (a0),(a2)+    ;InstrExt.hold -> holdvals
  1282.         adda.w    d0,a0        ;ptr to next InstrExt
  1283.         dbf    d2,IM_loop1
  1284.         bra.s    IM_exit
  1285. IM_clrhlddec    moveq    #125,d0        ;no InstrExt => clear holdvals/decays
  1286. IM_loop2    clr.b    (a2)+
  1287.         dbf    d0,IM_loop2
  1288. IM_exit        movem.l    (sp)+,a2-a3/d2
  1289.         rts
  1290.  
  1291.  
  1292. ; *************************************************************************
  1293. ; ContModule8(a0 = module) -- continue playing
  1294. ; *************************************************************************
  1295. _ContModule8    bsr.w    _End8Play
  1296.         moveq    #0,d0
  1297.         bra.s    contpoint8
  1298. ; *************************************************************************
  1299. ; PlayModule8(a0 = module)  -- init and play a module
  1300. ; *************************************************************************
  1301. _PlayModule8:    st    d0
  1302. contpoint8    move.l    a6,-(sp)
  1303.         lea    DB,a6
  1304.         movem.l    a0/d0,-(sp)
  1305.         bsr    _InitModule8
  1306.         movem.l    (sp)+,a0/d0
  1307.     IFNE    AUDDEV
  1308.         tst.b    audiodevopen-DB(a6)
  1309.         beq.s    PM_end        ;resource allocation failure
  1310.     ENDC
  1311.         move.l    a0,d1
  1312.         beq.s    PM_end        ;module failure
  1313.         bsr.w    _End8Play
  1314.         clr.l    _module8-DB(a6)
  1315.         move.w    _modnum8,d1
  1316.         beq.s    PM_modfound
  1317. PM_nextmod    tst.l    mmd_expdata(a0)
  1318.         beq.s    PM_modfound
  1319.         move.l    mmd_expdata(a0),a1
  1320.         tst.l    (a1)
  1321.         beq.s    PM_modfound        ;no more modules here!
  1322.         move.l    (a1),a0
  1323.         subq.w    #1,d1
  1324.         bgt.s    PM_nextmod
  1325. PM_modfound    movea.l    mmd_songinfo(a0),a1        ;song
  1326.         move.b    msng_tempo2(a1),mmd_counter(a0)    ;init counter
  1327.         btst    #0,msng_flags(a1)
  1328.         bne.s    PM_filon
  1329.         bset    #1,$bfe001
  1330.         bra.s    PM_filset
  1331. PM_filon    bclr    #1,$bfe001
  1332. PM_filset    tst.b    d0
  1333.         beq.s    PM_noclr
  1334.         clr.l    mmd_pline(a0)
  1335. PM_noclr    move.w    mmd_pseqnum(a0),d1
  1336.         add.w    #msng_playseq,d1
  1337.         move.b    0(a1,d1.w),d1
  1338.         move.b    d1,mmd_pblock+1(a0)
  1339.         move.w    #-1,mmd_pstate(a0)
  1340.         move.l    a0,_module8-DB(a6)
  1341.         move.l    mmd_expdata(a0),d0
  1342.         beq.s    PM_start
  1343.         movea.l    d0,a0
  1344.         lea    36(a0),a0    ;track split mask
  1345.         bsr.s    _SetChMode
  1346. PM_start    bsr.s    _Start8Play
  1347. PM_end        move.l    (sp)+,a6
  1348.         rts
  1349.  
  1350. _SetChMode    ;a0 = address of 4 UBYTEs
  1351.         movem.l    a2/d2,-(sp)
  1352.         lea    trksplit-DB(a6),a2
  1353.         lea    t038+trk_split-DB(a6),a1
  1354.         moveq    #3,d0
  1355.         moveq    #0,d1
  1356. scm_loop    lsr.b    #1,d1
  1357.         move.b    (a0)+,d2
  1358.         beq.s    scm_split
  1359.         moveq    #0,d2
  1360.         bra.s    scm_nosplit
  1361. scm_split    or.b    #8,d1
  1362.         st    d2
  1363. scm_nosplit    move.b    d2,(a1)
  1364.         move.b    d2,4*T03SZ(a1)
  1365.         lea    T03SZ(a1),a1
  1366.         move.b    d2,(a2)+
  1367.         dbf    d0,scm_loop
  1368.         move.w    d1,chdmamask-DB(a6)
  1369.         movem.l    (sp)+,a2/d2
  1370. rts:        rts
  1371.  
  1372. _Start8Play:    ;d0 = pstate
  1373.         lea    _audiobuff,a0
  1374.         move.w    #1600-1,d1
  1375. clrbuffloop:    clr.w    (a0)+        ;clear track buffers
  1376.         dbf    d1,clrbuffloop
  1377.         move.l    _module8-DB(a6),d0
  1378.         beq.s    rts
  1379.         move.l    d0,a0
  1380.         movea.l    mmd_songinfo(a0),a0
  1381.         move.w    msng_deftempo(a0),d0    ;get deftempo
  1382.         bsr.w    _SetTempo
  1383.         lea    $dff000,a0
  1384.         move.w    currchsize2-DB(a6),d0
  1385.         move.w    d0,$a4(a0)    ;set audio buffer sizes
  1386.         move.w    d0,$b4(a0)    ;according to tempo selection
  1387.         move.w    d0,$c4(a0)
  1388.         move.w    d0,$d4(a0)
  1389.         move.w    #227,d1
  1390.         move.w    d1,$a6(a0)
  1391.         move.w    d1,$b6(a0)
  1392.         move.w    d1,$c6(a0)
  1393.         move.w    d1,$d6(a0)
  1394.         move.l    #_audiobuff,$a0(a0)
  1395.         move.l    #_audiobuff+800,$b0(a0)
  1396.         move.l    #_audiobuff+1600,$c0(a0)
  1397.         move.l    #_audiobuff+2400,$d0(a0)
  1398.         moveq    #64,d1
  1399.         move.w    d1,$a8(a0)
  1400.         move.w    d1,$b8(a0)
  1401.         move.w    d1,$c8(a0)
  1402.         move.w    d1,$d8(a0)
  1403.         clr.b    whichbuff-DB(a6)
  1404.         movea.l    4,a1
  1405.         move.w    #$4000,$9a(a0)
  1406.         addq.b    #1,$126(a1)
  1407.         lea    track0hw-DB(a6),a1
  1408.         moveq    #7,d1
  1409. clrtrkloop    clr.l    (a1)
  1410.         clr.w    ac_per(a1)
  1411.         adda.w    #SIZE4TRKHW/4,a1
  1412.         dbf    d1,clrtrkloop
  1413.         move.w    #$F,$dff096    ;audio DMA off
  1414.         bsr.w    _Wait1line    ;wait until all stopped
  1415.         st    play8-DB(a6)
  1416.         move.w    #$8080,$9a(a0)
  1417.         move.w    chdmamask-DB(a6),d1
  1418.         bset    #15,d1
  1419.         move.w    d1,$96(a0)
  1420.         movea.l    4,a1
  1421.         subq.b    #1,$126(a1)
  1422.         bge.s    x8play
  1423.         move.w    #$c000,$9a(a0)
  1424. x8play        rts
  1425. ; *************************************************************************
  1426. ; InitPlayer8() -- allocate interrupt, audio, serial port etc...
  1427. ; *************************************************************************
  1428. _InitPlayer8:    bsr.s    _AudioInit
  1429.         tst.l    d0
  1430.         bne.s    IP_error
  1431.         rts
  1432. IP_error    bsr.s    _RemPlayer8
  1433.         moveq    #-1,d0
  1434.         rts
  1435. ; *************************************************************************
  1436. ; StopPlayer8() -- stop music
  1437. ; *************************************************************************
  1438. _StopPlayer8:    move.l    _module8,d0
  1439.         beq.s    SP_nomod
  1440.         movea.l    d0,a0
  1441.         clr.w    mmd_pstate(a0)
  1442.         clr.l    _module8
  1443. SP_nomod    bra.w    _End8Play
  1444.  
  1445. ; *************************************************************************
  1446. ; RemPlayer8() -- free interrupt, audio, serial port etc..
  1447. ; *************************************************************************
  1448. _RemPlayer8:    bsr.s    _StopPlayer8
  1449. ;        vvvvvvvvvvvvvvvv  to _AudioRem
  1450. ; *************************************************************************
  1451. _AudioRem:    movem.l    a5-a6,-(sp)
  1452.         lea    DB,a5
  1453.         bsr.w    _Rem8chan
  1454.     IFNE    AUDDEV
  1455.         movea.l    4,a6
  1456.         tst.b    audiodevopen-DB(a5)
  1457.         beq.s    rem2
  1458.         clr.b    audiodevopen-DB(a5)
  1459.         move.w    #$000f,$dff096    ;stop audio DMA
  1460. ;    +=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+ close audio.device
  1461.         lea    allocreq-DB(a5),a1
  1462.         jsr    -$1c2(a6)    ;CloseDevice()
  1463. rem2:        moveq    #0,d0
  1464.         move.b    sigbitnum-DB(a5),d0
  1465.         bmi.s    rem3
  1466. ;    +=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+ free signal bit
  1467.         jsr    -$150(a6)    ;FreeSignal()
  1468.         st    sigbitnum-DB(a5)
  1469.     ENDC
  1470. rem3:        movem.l    (sp)+,a5-a6
  1471.         rts
  1472.  
  1473. _AudioInit:    movem.l    a4/a6/d2-d3,-(sp)
  1474.         lea    DB,a4
  1475.         movea.l    4,a6
  1476.     IFNE    AUDDEV
  1477.         moveq    #0,d2
  1478. ;    +=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+ alloc signal bit
  1479.         moveq    #1,d2
  1480.         moveq    #-1,d0
  1481.         jsr    -$14a(a6)    ;AllocSignal()
  1482.         tst.b    d0
  1483.         bmi.w    initerr
  1484.         move.b    d0,sigbitnum-DB(a4)
  1485. ;    +=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+ prepare IORequest
  1486.         lea    allocport-DB(a4),a1
  1487.         move.b    d0,15(a1)    ;set mp_SigBit
  1488.         move.l    a1,-(sp)
  1489.         suba.l    a1,a1
  1490.         jsr    -$126(a6)    ;FindTask(0)
  1491.         move.l    (sp)+,a1
  1492.         move.l    d0,16(a1)    ;set mp_SigTask
  1493.         lea    reqlist-DB(a4),a0
  1494.         move.l    a0,(a0)        ;NEWLIST begins...
  1495.         addq.l    #4,(a0)
  1496.         clr.l    4(a0)
  1497.         move.l    a0,8(a0)    ;NEWLIST ends...
  1498. ;    +=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+ open audio.device
  1499.         moveq    #2,d2
  1500.         lea    allocreq-DB(a4),a1
  1501.         lea    audiodevname-DB(a4),a0
  1502.         moveq    #0,d0
  1503.         moveq    #0,d1
  1504.         jsr    -$1bc(a6)    ;OpenDevice()
  1505.         tst.b    d0
  1506.         bne.w    initerr
  1507.         st.b    audiodevopen-DB(a4)
  1508.     ENDC
  1509.         move.w    #1<<7,$dff09a    ;Init 8 channel stuff
  1510.         moveq    #7,d0        ;Audio channel 0 interrupt
  1511.         lea    audiointerrupt-DB(a4),a1
  1512.         jsr    -$a2(a6)    ;SetIntVector()
  1513.         move.l    d0,prevaud-DB(a4)
  1514.         st    eightrkon-DB(a4)
  1515.         moveq    #0,d0
  1516. initret:    movem.l    (sp)+,a4/a6/d2-d3
  1517.         rts
  1518. initerr:    move.l    d2,d0
  1519.         bra.s    initret
  1520.  
  1521.         DATA    __MERGED
  1522. DB:        ;Data base pointer
  1523.     IFNE    AUDDEV
  1524. sigbitnum    dc.b    -1
  1525. audiodevopen    dc.b    0
  1526. allocm        dc.b    $F,0
  1527.     ENDC
  1528. chdmamask    dc.w    0
  1529. trksplit    dc.b    0,0,0,0
  1530.         even
  1531.     IFNE    AUDDEV
  1532. allocport    dc.l    0,0    ;succ, pred
  1533.         dc.b    4,0    ;NT_MSGPORT
  1534.         dc.l    0    ;name
  1535.         dc.b    0,0    ;flags = PA_SIGNAL
  1536.         dc.l    0    ;task
  1537. reqlist        dc.l    0,0,0    ;list head, tail and tailpred
  1538.         dc.b    5,0
  1539. allocreq    dc.l    0,0
  1540.         dc.b    0,127    ;NT_UNKNOWN, use maximum priority (127)
  1541.         dc.l    0,allocport    ;name, replyport
  1542.         dc.w    68        ;length
  1543.         dc.l    0    ;io_Device
  1544.         dc.l    0    ;io_Unit
  1545.         dc.w    0    ;io_Command
  1546.         dc.b    0,0    ;io_Flags, io_Error
  1547.         dc.w    0    ;ioa_AllocKey
  1548.         dc.l    allocm    ;ioa_Data
  1549.         dc.l    1    ;ioa_Length
  1550.         dc.w    0,0,0    ;ioa_Period, Volume, Cycles
  1551.         dc.w    0,0,0,0,0,0,0,0,0,0    ;ioa_WriteMsg
  1552. audiodevname    dc.b    'audio.device',0
  1553.     ENDC
  1554.         even
  1555.  
  1556. zerodata    dc.w    0
  1557. whichbuff    dc.w    0
  1558.  
  1559. track0hw    dc.l    0,0,$dff0a9,0,0
  1560.         dc.w    $0001,$df,$f0a0
  1561. track1hw    dc.l    0,0,$dff0b9,0,0
  1562.         dc.w    $0002,$df,$f0b0
  1563. track2hw    dc.l    0,0,$dff0c9,0,0
  1564.         dc.w    $0004,$df,$f0c0
  1565. track3hw    dc.l    0,0,$dff0d9,0,0
  1566.         dc.w    $0008,$df,$f0d0
  1567. track4hw    dc.l    0,0,$dff0a9,0,0
  1568.         dc.w    0,0,0
  1569. track5hw    dc.l    0,0,$dff0b9,0,0
  1570.         dc.w    0,0,0
  1571. track6hw    dc.l    0,0,$dff0c9,0,0
  1572.         dc.w    0,0,0
  1573. track7hw    dc.l    0,0,$dff0d9,0,0
  1574.         dc.w    0,0,0
  1575. SIZE4TRKHW    equ    4*$1A
  1576.  
  1577. audintname    dc.b    'OctaMED AudioInterrupt',0
  1578.         even
  1579. audiointerrupt    dc.w    0,0,0,0,0
  1580.         dc.l    audintname,_audiobuff,_IntHandler8
  1581. prevaud        dc.l    0
  1582. play8        dc.b    0
  1583. eightrkon    dc.b    0
  1584.  
  1585. t038:        ds.b    22
  1586.         dc.l    track0hw
  1587.         ds.b    71
  1588.         dc.b    $ff
  1589.         ds.b    22
  1590.         dc.l    track1hw
  1591.         ds.b    71
  1592.         dc.b    $ff
  1593.         ds.b    22
  1594. t238        dc.l    track2hw
  1595.         ds.b    71
  1596.         dc.b    $ff
  1597.         ds.b    22
  1598.         dc.l    track3hw
  1599.         ds.b    71
  1600.         dc.b    $ff
  1601. t4158        ds.b    22
  1602.         dc.l    track4hw
  1603.         ds.b    71
  1604.         dc.b    $ff
  1605.         ds.b    22
  1606.         dc.l    track5hw
  1607.         ds.b    71
  1608.         dc.b    $ff
  1609.         ds.b    22
  1610. t6158        dc.l    track6hw
  1611.         ds.b    71
  1612.         dc.b    $ff
  1613.         ds.b    22
  1614.         dc.l    track7hw
  1615.         ds.b    71
  1616.         dc.b    $ff
  1617.  
  1618. trackdata8    dc.l    t038,t038+T03SZ,t038+2*T03SZ,t038+3*T03SZ
  1619.         dc.l    t4158,t4158+T03SZ,t4158+2*T03SZ,t4158+3*T03SZ
  1620.  
  1621. blkdelay    dc.w    0    ;block delay (PT PatternDelay)
  1622.  
  1623. eightchsizes    dc.b    110,120,130,140,150,160,170,180,190,200
  1624. currchsize    dc.w    0    ;<< 3
  1625. currchsize2    dc.w    0
  1626. currchszcnt    dc.w    0
  1627.  
  1628. nextblock    dc.b    0 ;\ DON'T SEPARATE
  1629. nxtnoclrln    dc.b    0 ;/
  1630. numtracks    dc.w    0
  1631. numlines    dc.w    0
  1632. nextblockline    dc.w    0
  1633. rptline        dc.w    0
  1634. rptcounter    dc.w    0
  1635. _module8    dc.l    0
  1636.  
  1637.         EVEN
  1638. holdvals    ds.b    63
  1639.         ds.b    63    ;finetune
  1640.  
  1641. per0    dc.w    856,808,762,720,678,640,604,570,538,508,480,453
  1642.     dc.w    428,404,381,360,339,320,302,285,269,254,240,226
  1643.     dc.w    214,202,190,180,170,160,151,143,135,127,120,113
  1644.     dc.w    214,202,190,180,170,160,151,143,135,127,120,113
  1645.     dc.w    214,202,190,180,170,160,151,143,135,127,120,113
  1646.     dc.w    214,202,190,180,170,160,151,143,135,127,120,113
  1647. per1    dc.w    850,802,757,715,674,637,601,567,535,505,477,450
  1648.     dc.w    425,401,379,357,337,318,300,284,268,253,239,225
  1649.     dc.w    213,201,189,179,169,159,150,142,134,126,119,113
  1650.     dc.w    213,201,189,179,169,159,150,142,134,126,119,113
  1651.     dc.w    213,201,189,179,169,159,150,142,134,126,119,113
  1652.     dc.w    213,201,189,179,169,159,150,142,134,126,119,113
  1653. per2    dc.w    844,796,752,709,670,632,597,563,532,502,474,447
  1654.     dc.w    422,398,376,355,335,316,298,282,266,251,237,224
  1655.     dc.w    211,199,188,177,167,158,149,141,133,125,118,112
  1656.     dc.w    211,199,188,177,167,158,149,141,133,125,118,112
  1657.     dc.w    211,199,188,177,167,158,149,141,133,125,118,112
  1658.     dc.w    211,199,188,177,167,158,149,141,133,125,118,112
  1659. per3    dc.w    838,791,746,704,665,628,592,559,528,498,470,444
  1660.     dc.w    419,395,373,352,332,314,296,280,264,249,235,222
  1661.     dc.w    209,198,187,176,166,157,148,140,132,125,118,111
  1662.     dc.w    209,198,187,176,166,157,148,140,132,125,118,111
  1663.     dc.w    209,198,187,176,166,157,148,140,132,125,118,111
  1664.     dc.w    209,198,187,176,166,157,148,140,132,125,118,111
  1665. per4    dc.w    832,785,741,699,660,623,588,555,524,495,467,441
  1666.     dc.w    416,392,370,350,330,312,294,278,262,247,233,220
  1667.     dc.w    208,196,185,175,165,156,147,139,131,124,117,110
  1668.     dc.w    208,196,185,175,165,156,147,139,131,124,117,110
  1669.     dc.w    208,196,185,175,165,156,147,139,131,124,117,110
  1670.     dc.w    208,196,185,175,165,156,147,139,131,124,117,110
  1671. per5    dc.w    826,779,736,694,655,619,584,551,520,491,463,437
  1672.     dc.w    413,390,368,347,328,309,292,276,260,245,232,219
  1673.     dc.w    206,195,184,174,164,155,146,138,130,123,116,109
  1674.     dc.w    206,195,184,174,164,155,146,138,130,123,116,109
  1675.     dc.w    206,195,184,174,164,155,146,138,130,123,116,109
  1676.     dc.w    206,195,184,174,164,155,146,138,130,123,116,109
  1677. per6    dc.w    820,774,730,689,651,614,580,547,516,487,460,434
  1678.     dc.w    410,387,365,345,325,307,290,274,258,244,230,217
  1679.     dc.w    205,193,183,172,163,154,145,137,129,122,115,109
  1680.     dc.w    205,193,183,172,163,154,145,137,129,122,115,109
  1681.     dc.w    205,193,183,172,163,154,145,137,129,122,115,109
  1682.     dc.w    205,193,183,172,163,154,145,137,129,122,115,109
  1683. per7    dc.w    814,768,725,684,646,610,575,543,513,484,457,431
  1684.     dc.w    407,384,363,342,323,305,288,272,256,242,228,216
  1685.     dc.w    204,192,181,171,161,152,144,136,128,121,114,108
  1686.     dc.w    204,192,181,171,161,152,144,136,128,121,114,108
  1687.     dc.w    204,192,181,171,161,152,144,136,128,121,114,108
  1688.     dc.w    204,192,181,171,161,152,144,136,128,121,114,108
  1689. per_8    dc.w    907,856,808,762,720,678,640,604,570,538,508,480
  1690.     dc.w    453,428,404,381,360,339,320,302,285,269,254,240
  1691.     dc.w    226,214,202,190,180,170,160,151,143,135,127,120
  1692.     dc.w    226,214,202,190,180,170,160,151,143,135,127,120
  1693.     dc.w    226,214,202,190,180,170,160,151,143,135,127,120
  1694.     dc.w    226,214,202,190,180,170,160,151,143,135,127,120
  1695. per_7    dc.w    900,850,802,757,715,675,636,601,567,535,505,477
  1696.     dc.w    450,425,401,379,357,337,318,300,284,268,253,238
  1697.     dc.w    225,212,200,189,179,169,159,150,142,134,126,119
  1698.     dc.w    225,212,200,189,179,169,159,150,142,134,126,119
  1699.     dc.w    225,212,200,189,179,169,159,150,142,134,126,119
  1700.     dc.w    225,212,200,189,179,169,159,150,142,134,126,119
  1701. per_6    dc.w    894,844,796,752,709,670,632,597,563,532,502,474
  1702.     dc.w    447,422,398,376,355,335,316,298,282,266,251,237
  1703.     dc.w    223,211,199,188,177,167,158,149,141,133,125,118
  1704.     dc.w    223,211,199,188,177,167,158,149,141,133,125,118
  1705.     dc.w    223,211,199,188,177,167,158,149,141,133,125,118
  1706.     dc.w    223,211,199,188,177,167,158,149,141,133,125,118
  1707. per_5    dc.w    887,838,791,746,704,665,628,592,559,528,498,470
  1708.     dc.w    444,419,395,373,352,332,314,296,280,264,249,235
  1709.     dc.w    222,209,198,187,176,166,157,148,140,132,125,118
  1710.     dc.w    222,209,198,187,176,166,157,148,140,132,125,118
  1711.     dc.w    222,209,198,187,176,166,157,148,140,132,125,118
  1712.     dc.w    222,209,198,187,176,166,157,148,140,132,125,118
  1713. per_4    dc.w    881,832,785,741,699,660,623,588,555,524,494,467
  1714.     dc.w    441,416,392,370,350,330,312,294,278,262,247,233
  1715.     dc.w    220,208,196,185,175,165,156,147,139,131,123,117
  1716.     dc.w    220,208,196,185,175,165,156,147,139,131,123,117
  1717.     dc.w    220,208,196,185,175,165,156,147,139,131,123,117
  1718.     dc.w    220,208,196,185,175,165,156,147,139,131,123,117
  1719. per_3    dc.w    875,826,779,736,694,655,619,584,551,520,491,463
  1720.     dc.w    437,413,390,368,347,328,309,292,276,260,245,232
  1721.     dc.w    219,206,195,184,174,164,155,146,138,130,123,116
  1722.     dc.w    219,206,195,184,174,164,155,146,138,130,123,116
  1723.     dc.w    219,206,195,184,174,164,155,146,138,130,123,116
  1724.     dc.w    219,206,195,184,174,164,155,146,138,130,123,116
  1725. per_2    dc.w    868,820,774,730,689,651,614,580,547,516,487,460
  1726.     dc.w    434,410,387,365,345,325,307,290,274,258,244,230
  1727.     dc.w    217,205,193,183,172,163,154,145,137,129,122,115
  1728.     dc.w    217,205,193,183,172,163,154,145,137,129,122,115
  1729.     dc.w    217,205,193,183,172,163,154,145,137,129,122,115
  1730.     dc.w    217,205,193,183,172,163,154,145,137,129,122,115
  1731. per_1    dc.w    862,814,768,725,684,646,610,575,543,513,484,457
  1732.     dc.w    431,407,384,363,342,323,305,288,272,256,242,228
  1733.     dc.w    216,203,192,181,171,161,152,144,136,128,121,114
  1734.     dc.w    216,203,192,181,171,161,152,144,136,128,121,114
  1735.     dc.w    216,203,192,181,171,161,152,144,136,128,121,114
  1736.     dc.w    216,203,192,181,171,161,152,144,136,128,121,114
  1737.  
  1738. _periodtable
  1739.     dc.l    per_8,per_7,per_6,per_5,per_4,per_3,per_2,per_1,per0
  1740.     dc.l    per1,per2,per3,per4,per5,per6,per7
  1741.  
  1742.                 bss     "chip",chip
  1743.  
  1744. _audiobuff:    ds.w    200*8
  1745. _modnum8:    ds.w    1
  1746. _chipzero:    ds.w    1
  1747.  
  1748. ; the track-data structure definition:
  1749. trk_prevnote    EQU    0    ;previous note number
  1750. trk_previnstr    EQU    1    ;previous instrument number
  1751. trk_prevvol    EQU    2    ;previous volume
  1752. trk_prevmidich    EQU    3    ;previous MIDI channel
  1753. trk_cmd        EQU    4    ;command (the 3rd number from right)
  1754. trk_cmdqual    EQU    5    ;command qualifier (infobyte, databyte..)
  1755. trk_prevmidin    EQU    6    ;previous MIDI note
  1756. trk_noteoffcnt    EQU    7    ;note-off counter (hold)
  1757. trk_inithold    EQU    8    ;default hold for this instrument
  1758. trk_initdecay    EQU    9    ;default decay for....
  1759. trk_stransp    EQU    10    ;instrument transpose
  1760. trk_finetune    EQU    11    ;finetune
  1761. trk_soffset    EQU    12    ;new sample offset
  1762. trk_previnstra    EQU    14    ;address of the previous instrument data
  1763. trk_trackvol    EQU    18
  1764. ;    the following data only on tracks 0 - 3
  1765. trk_prevper    EQU    20    ;previous period
  1766. trk_audioaddr    EQU    22    ;hardware audio channel base address
  1767. trk_sampleptr    EQU    26    ;pointer to sample
  1768. trk_samplelen    EQU    30    ;length (>> 1)
  1769. trk_porttrgper    EQU    32    ;portamento (cmd 3) target period
  1770. trk_vibshift    EQU    34    ;vibrato shift for ASR instruction
  1771. trk_vibrspd    EQU    35    ;vibrato speed/size (cmd 4 qualifier)
  1772. trk_vibrsz    EQU    36    ;vibrato size
  1773. trk_synthptr    EQU    38    ;pointer to synthetic/hybrid instrument
  1774. trk_arpgoffs    EQU    42    ;SYNTH: current arpeggio offset
  1775. trk_arpsoffs    EQU    44    ;SYNTH: arpeggio restart offset
  1776. trk_volxcnt    EQU    46    ;SYNTH: volume execute counter
  1777. trk_wfxcnt    EQU    47    ;SYNTH: waveform execute counter
  1778. trk_volcmd    EQU    48    ;SYNTH: volume command pointer
  1779. trk_wfcmd    EQU    50    ;SYNTH: waveform command pointer
  1780. trk_volwait    EQU    52    ;SYNTH: counter for WAI (volume list)
  1781. trk_wfwait    EQU    53    ;SYNTH: counter for WAI (waveform list)
  1782. trk_synthvibspd    EQU    54    ;SYNTH: vibrato speed
  1783. trk_wfchgspd    EQU    56    ;SYNTH: period change
  1784. trk_perchg    EQU    58    ;SYNTH: curr. period change from trk_prevper
  1785. trk_envptr    EQU    60    ;SYNTH: envelope waveform pointer
  1786. trk_synvibdep    EQU    64    ;SYNTH: vibrato depth
  1787. trk_synvibwf    EQU    66       ;SYNTH: vibrato waveform
  1788. trk_synviboffs    EQU    70    ;SYNTH: vibrato pointer
  1789. trk_initvolxspd    EQU    72    ;SYNTH: volume execute speed
  1790. trk_initwfxspd    EQU    73    ;SYNTH: waveform execute speed
  1791. trk_volchgspd    EQU    74    ;SYNTH: volume change
  1792. trk_prevnote2    EQU    75    ;SYNTH: previous note
  1793. trk_synvol    EQU    76    ;SYNTH: current volume
  1794. trk_synthtype    EQU    77    ;>0 = synth, -1 = hybrid, 0 = no synth
  1795. trk_periodtbl    EQU    78    ;pointer to period table
  1796. trk_prevportspd    EQU    82    ;portamento (cmd 3) speed
  1797. trk_decay    EQU    84    ;decay
  1798. trk_fadespd    EQU    85    ;decay speed
  1799. trk_envrestart    EQU    86    ;SYNTH: envelope waveform restart point
  1800. trk_envcount    EQU    90    ;SYNTH: envelope counter
  1801. trk_split    EQU    91    ;0 = this channel not splitted (OctaMED V2)
  1802. trk_vibroffs    EQU    92    ;vibrato table offset \ DON'T SEPARATE
  1803. trk_tremoffs    EQU    93    ;tremolo table offset /
  1804. trk_tremsz    EQU    94    ;tremolo size
  1805. trk_tremspd    EQU    96    ;tremolo speed
  1806. trk_tempvol    EQU    97    ;temporary volume (for tremolo)
  1807.         END
  1808.